/* Janus Chat - Version 1.0
 * Authors: Matthew Perry
 *          Michael Freid
 *          Marc Latou
 *          Richard Lee
 *
 * The Janus Chat Client is a highly secured
 * peer-to-peer chat client designed to facilitate
 * the transfer of sensitive data or as a communication
 * medium for the extra paranoid
 *
 * This file contains the implementation for a User class.
 * This class will serve as holder of preferences and the
 * encryption key of the current user */

#include "user.h"
#include "message.h"
#include "exceptions.h"
#include <utility>
using std::pair;

/* The User constructor:
 * Basic constructor that assings a name
 * and generates RSA keys for encrypted
 * chat. */
User::User( const string& moniker )
{
    myMoniker = moniker;

    // Generate a public and private key
    pair<jRsa::publicKey,jRsa::privateKey> keys;
    keys = jRsa::generateKeys( 1024 );
    myPublicKey = keys.first;
    myPrivateKey = keys.second;
}

/* The User constructor:
 * this constructor takes a name and a public key
 * and creates a User class that would be used for
 * keeping info on a peer */
User::User( const string& moniker, jRsa::publicKey key )
{
    myMoniker = moniker;
    myPublicKey = key;
}

/* The getMoniker function:
 * returns this user's moniker */
string User::getMoniker() const
{
    return myMoniker;
}

/* The setMoniker function:
 * sets this user's moniker */
void User::setMoniker( const string& moniker )
{
    if( moniker.size() > Message::MONIKER_SIZE )
        throw new MessageException( "User Moniker is too long" );

    myMoniker = moniker;
}

/* The getPublicKey function:
 * returns this user's publicKey */
jRsa::publicKey User::getPublicKey() const
{
    return myPublicKey;
}

/* The getPrivateKey function:
 * returns this user's privateKey */
jRsa::privateKey User::getPrivateKey() const
{
    return myPrivateKey;
}

